﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using RedemptoristRetreatCenter.DatabaseUtility;

namespace RedemptoristRetreatCenter.Account
{
    public partial class Register : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];
        }

        private Boolean doesUserExist(String username)
        {
            UserAccountUtility userAccountUtil = new RedemptoristRetreatCenter.DatabaseUtility.UserAccountUtility();
            //Session.Add("User", RegisterUser.UserName);
            return userAccountUtil.userExists(username);
        }

        private Boolean passwordsMatch(String password1, String password2)
        {
            return password1.Equals(password2);
        }

        protected void Register_Click(object sender, EventArgs e)
        {
            if (doesUserExist(UserName.Text))
                ErrorMessage.Text = "Username already exists. Please choose a new username";

            if (!(passwordsMatch(Password.Text, ConfirmPassword.Text)))
                ErrorMessage.Text = "These passwords do not match. Please re-enter your password";


            //FormsAuthentication.SetAuthCookie(RegisterUser.UserName, createPersistentCookie: false);

            //string continueUrl = RegisterUser.ContinueDestinationPageUrl;
            //if (!OpenAuth.IsLocalUrl(continueUrl))
            //{
            //    continueUrl = "~/";
            //}
            //Response.Redirect(continueUrl);
        }
    }
}